//
// Created by asus on 2017/11/17.
//
#include <jni.h>
#include <string>
#include<android/bitmap.h>
#include <android/log.h>
#define LIBNAME "native-lib"
#ifndef eprintf
#define eprintf(...) __android_log_print(ANDROID_LOG_ERROR,LIBNAME,__VA_ARGS__)
#endif

#define RGBA_A(p) (((p) & 0xFF000000) >> 24)
#define RGBA_R(p) (((p) & 0x00FF0000) >> 16)
#define RGBA_G(p) (((p) & 0x0000FF00) >>  8)
#define RGBA_B(p)  ((p) & 0x000000FF)
#define MAKE_RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

extern "C" {
JNIEXPORT jboolean
JNICALL Java_cn_liuyin_ndk_MyNdkTool_toHeiBai(JNIEnv *env, jclass clazz,
                                              jobject bmpObj) {
    AndroidBitmapInfo bmpInfo;
    if(ANDROID_BITMAP_RESULT_SUCCESS!=AndroidBitmap_getInfo(env,bmpObj,&bmpInfo))
    {
        eprintf("get bitmap info failed");
        return (jboolean) false;
    }
    int* dataFromBmp=NULL;
    if(AndroidBitmap_lockPixels(env,bmpObj,(void**)&dataFromBmp))
    {return (jboolean) false;}

    AndroidBitmap_unlockPixels(env,bmpObj);
    return (jboolean) true;



}

JNIEXPORT jstring
JNICALL Java_cn_liuyin_ndk_MyNdkTool_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    eprintf("get bitmap info failed");
    return env->NewStringUTF(hello.c_str());
}
}
